package hn.sigit.dao.hnd.ladmshadow;

import java.util.List;

import org.hibernate.Criteria;
import org.hibernate.Session;
import org.hibernate.criterion.Restrictions;
import org.jboss.seam.Component;

import hn.sigit.model.hnd.ladmshadow.Party;
import hn.sigit.model.ladm.external.ExtParty;
import hn.sigit.dao.SigitDAO;

public class PartyDAO extends SigitDAO<Party> {
	private static final long serialVersionUID = 1L;
	
	protected PartyDAO() {
		
	}
	
	
	public static Party loadPartyByExtParty(ExtParty extParty) {
		Session commonsDatabase = (Session)Component.getInstance(COMMONS_DB);
		return loadPartyByExtParty(commonsDatabase, extParty);
	}
	public static List<Party> loadPartyByExtPartySubType(Class<ExtParty> cls) {
		Session commonsDatabase = (Session)Component.getInstance(COMMONS_DB);
		return loadPartyByExtPartySubType(commonsDatabase, cls);
	}
	
	public static Party loadPartyByExtParty(Session session, ExtParty extParty) {
		Criteria criteria = session.createCriteria(Party.class);
		criteria.add(Restrictions.eq("extParty", extParty));
		
		return (Party)criteria.uniqueResult();
	}
	@SuppressWarnings("unchecked")
	public static List<Party> loadPartyByExtPartySubType(Session session, Class<ExtParty> cls) {
		Criteria criteria = session.createCriteria(Party.class);
		criteria.add(Restrictions.eq("extParty.class.canonicalName", cls.getCanonicalName()));
		
		return (List<Party>)criteria.list();
	}
/*
	public Party createParty() {
		return new Party();
	}
	
	public void save(Party party) {
		commonsDatabase.saveOrUpdate(party);
	}
	
	public void delete(Party party) {
		commonsDatabase.delete(party);
	}*/
}
